﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.Text;
namespace Microsoft.TownHall.ServiceClient
{
    public delegate void CategoriesDownloadedEventHandler(object sender, CategoriesDownloadedEventArgs e);
    public delegate void QuestionPostedEventHandler(object sender, QuestionPostedEventArgs e);
    public delegate void SignInEventHandler(object sender, SignInCompletedEventArgs e);
    public delegate void RegistrationEventHandler(object sender, RegistrationCompletedEventArgs e);
    public delegate void TopicsDownloadedEventHandler(object sender, TopicsDownloadedEventArgs e);
    public delegate void QuestionsDownloadedEventHandler(object sender, QuestionsDownloadedEventArgs e);
    public delegate void TagsDownloadedEventHandler(object send, TagsDownloadedEventArgs e);
    public delegate void UsersDownloadedEventHandler(object send, UsersDownloadedEventArgs e);


    public class THServiceClient
    {
        public const string BASE_URL = "http://beamartian.jpl.nasa.gov";

        private CookieContainer cookieContainer = null;

        public event SignInEventHandler SignInCompleted;
        public event RegistrationEventHandler RegistrationCompleted;
        public event QuestionPostedEventHandler QuestionPosted;
        public event CategoriesDownloadedEventHandler CategoriesDownloaded;
        public event TopicsDownloadedEventHandler TopicsDownloaded;
        public event QuestionsDownloadedEventHandler QuestionsDownloaded;
        public event TagsDownloadedEventHandler TagsDownloaded;
        public event UsersDownloadedEventHandler UsersDownloaded;        
 

        //Provided locally, but could potentially move to the cloud in future;
        public MoreItemList GetMoreItems()
        {

            MoreItemList moreItems = new MoreItemList();

            MoreItem mi = new MoreItem(@"images\icons\Users.png","Users","");
            MoreItem mi1 = new MoreItem(@"images\icons\tags.png", "Tags", "");
            MoreItem mi2 = new MoreItem(@"images\icons\help.png", "Help", "");
            MoreItem mi3 = new MoreItem(@"images\icons\terms.png", "Terms", "");
            MoreItem mi4 = new MoreItem(@"images\icons\share.png", "Share This App", "");
            moreItems.Add(mi);
            moreItems.Add(mi1);
            moreItems.Add(mi2);
            moreItems.Add(mi3);
            moreItems.Add(mi4);
            return moreItems;
        
        }



        public  void GetCategories()
        {
            CategoryList categories = new CategoryList();

            string restUrl = BASE_URL + "/categories/all?format=xml";

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(restUrl)); 
            request.BeginGetResponse(new AsyncCallback(DownloadCategoryListCompleted), request);
        }
        
        public void Login(string username, string password)
        {
            string uri = String.Format("{0}/account/authenticate?format=xml", BASE_URL);
            UriBuilder httpHandlerUrlBuilder = new UriBuilder(uri);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(httpHandlerUrlBuilder.Uri);
            request.CookieContainer = new CookieContainer();
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded; charset=utf-8";

            request.BeginGetRequestStream(new AsyncCallback(delegate(IAsyncResult asyncResult)
            {
                try
                {
                    HttpWebRequest request2 = asyncResult.AsyncState as HttpWebRequest;
                    Stream postStream = request2.EndGetRequestStream(asyncResult);

                    string postData = String.Format("username={0}&Password={1}", username, password);
                    
                    byte[] byteArray = Encoding.UTF8.GetBytes(postData);

                    postStream.Write(byteArray, 0, postData.Length);
                    postStream.Close();

                    request.BeginGetResponse(new AsyncCallback(delegate(IAsyncResult asyncResult2)
                    {
                        try
                        {
                            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult2);
                            using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream()))
                            {
                                string resultString = streamReader1.ReadToEnd();

                                bool success = resultString.ToLower().Contains("<success>true</success>");
                                string userinfo = "";
                                User user = new User();

                                if (resultString.Contains("UserInfo"))
                                {
                                    int start = resultString.IndexOf("<UserInfo>") + 10;
                                    int len = resultString.IndexOf("</UserInfo>") - start;
                                    userinfo = resultString.Substring(start, len);
                                    user.UserID = int.Parse(userinfo.Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                                    user.Avatar = userinfo.Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries)[1];
                                    user.CitizenType = userinfo.Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries)[2];
                                }
                                      

                                cookieContainer = new CookieContainer();
                                cookieContainer.Add(new Uri(BASE_URL), response.Cookies);

                                if (SignInCompleted != null)
                                    SignInCompleted(this, new SignInCompletedEventArgs(success, "") { UserAccount = user });
                            }

                        }
                        catch (Exception e)
                        {
                            
                        }

                    }), request);
                }

                catch (Exception e)
                {
                    
                }
            }), request);

        }

        public void Register(User usr, string NewPassword, string ConfirmPassword)
        {
            string adultChild = usr.IsUnder13 ? "child" : "adult";
            string uri = String.Format("{0}/account/register-{1}/post?format=xml", BASE_URL, adultChild);
            UriBuilder httpHandlerUrlBuilder = new UriBuilder(uri);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(httpHandlerUrlBuilder.Uri);
            request.CookieContainer = new CookieContainer();
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded; charset=utf-8";

            request.BeginGetRequestStream(new AsyncCallback(delegate(IAsyncResult asyncResult)
            {
                try
                {
                    HttpWebRequest request2 = asyncResult.AsyncState as HttpWebRequest;
                    Stream postStream = request2.EndGetRequestStream(asyncResult);

                    string postData;                   
                    
                    if(usr.IsUnder13)
                        postData = String.Format("InfoAboutSelf=true&BeNice=true&NoBadWords=true&ParentEmail={0}&Email={0}&Username={1}&NewPassword={2}&ConfirmPassword={3}&PasswordQuestion=&PasswordAnswer=&PostalCode=&Zone=&avatar={4}&TermsOfUse=true&CitizenType={5}",
                        usr.Email, usr.DisplayName, NewPassword, ConfirmPassword, usr.Avatar, usr.CitizenType);
                    else
                        postData = String.Format("Email={0}&Username={1}&NewPassword={2}&ConfirmPassword={3}&PasswordQuestion=&PasswordAnswer=&PostalCode=&Zone=&avatar={4}&TermsOfUse=true&CitizenType={5}",
                            usr.Email, usr.DisplayName, NewPassword, ConfirmPassword, usr.Avatar, usr.CitizenType);    

                    byte[] byteArray = Encoding.UTF8.GetBytes(postData);

                    postStream.Write(byteArray, 0, postData.Length);
                    postStream.Close();

                    request.BeginGetResponse(new AsyncCallback(delegate(IAsyncResult asyncResult2)
                    {
                        try
                        {
                            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult2);
                            using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream()))
                            {
                                string resultString = streamReader1.ReadToEnd();

                                User user = new User();

                                if (resultString.Contains("UserID"))
                                {
                                    int start = resultString.IndexOf("<UserID>") + 8;
                                    int len = resultString.IndexOf("</UserID>") - start;
                                    user.UserID = int.Parse(resultString.Substring(start, len));

                                    start = resultString.IndexOf("<Avatar>") + 8;
                                    len = resultString.IndexOf("</Avatar>") - start;
                                    user.Avatar = resultString.Substring(start, len);

                                    start = resultString.IndexOf("<CitizenType>") + 13;
                                    len = resultString.IndexOf("</CitizenType>") - start;
                                    user.CitizenType = resultString.Substring(start, len);

                                    start = resultString.IndexOf("<DisplayName>") + 13;
                                    len = resultString.IndexOf("</DisplayName>") - start;
                                    user.DisplayName = resultString.Substring(start, len);
                                }

                                cookieContainer = new CookieContainer();
                                cookieContainer.Add(new Uri(BASE_URL), response.Cookies);

                                if (RegistrationCompleted != null)
                                    RegistrationCompleted(this, new RegistrationCompletedEventArgs(user));
                            }
                        }
                        catch (Exception e)
                        {
                            // DO response error handling
                        }

                    }), request);
                }

                catch (Exception e)
                {
                    // DO request error handling
                }
            }), request);

        }
        
        #region " PostQuestion "

        public void PostQuestion(string category, string body, string tagsCSV)
        {
            string uri = String.Format("{0}/questions/in/{1}/create/post?format=xml", BASE_URL, category);
            HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(new Uri(uri));

            if (cookieContainer == null)
            {
                webRequest.CookieContainer = new CookieContainer();
            }
            else
            {
                webRequest.CookieContainer = cookieContainer;
            }

            UriBuilder httpHandlerUrlBuilder = new UriBuilder(uri);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(httpHandlerUrlBuilder.Uri);
            request.CookieContainer = new CookieContainer();
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded; charset=utf-8";

            request.BeginGetRequestStream(new AsyncCallback(delegate(IAsyncResult asyncResult)
            {
                try
                {
                    HttpWebRequest request2 = asyncResult.AsyncState as HttpWebRequest;
                    Stream postStream = request2.EndGetRequestStream(asyncResult);
                    string parameters = String.Format("Body={0}&TagsCommaSeparated={1}&CategorySlug={2}", body, tagsCSV, category);

                    byte[] byteArray = Encoding.UTF8.GetBytes(parameters);

                    postStream.Write(byteArray, 0, parameters.Length);
                    postStream.Close();

                    request.BeginGetResponse(new AsyncCallback(delegate(IAsyncResult asyncResult2)
                    {
                        try
                        {
                            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult2);
                            using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream()))
                            {
                                string resultString = streamReader1.ReadToEnd();

                                object o = DeserializeCategoryList(resultString);
                                Nugget nugget = (Nugget)o;

                                cookieContainer = new CookieContainer();
                                cookieContainer.Add(new Uri(BASE_URL), response.Cookies);

                                if (QuestionPosted != null)
                                    QuestionPosted(this, new QuestionPostedEventArgs(nugget, DateTime.UtcNow));
                            }
                        }
                        catch (Exception e)
                        {
                            if (QuestionPosted != null)
                                QuestionPosted(this, new QuestionPostedEventArgs(new Nugget(), DateTime.UtcNow));
                        }

                    }), request);
                }

                catch (Exception e)
                {
                    // DO request error handling
                }
            }), request);

        }

        #endregion
        
        private void DownloadCategoryListCompleted(IAsyncResult asynchronousResult)
        {
            try
            {

                HttpWebRequest request =

                  (HttpWebRequest)asynchronousResult.AsyncState;

                HttpWebResponse response =

                  (HttpWebResponse)request.EndGetResponse(asynchronousResult);

                using (StreamReader streamReader1 =

                  new StreamReader(response.GetResponseStream()))
                {

                    string resultString = streamReader1.ReadToEnd();

                    object o = DeserializeCategoryList(resultString);
                    CategoryList categories = (CategoryList)o;

                    if (CategoriesDownloaded != null)
                        CategoriesDownloaded(this, new CategoriesDownloadedEventArgs(categories, DateTime.UtcNow));

                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }



        public  void GetTopicsForCategory(string categorySlug)
        {


            string restUrl = BASE_URL + "/topics/in/" + categorySlug + "?format=xml";

            HttpWebRequest request =

         (HttpWebRequest)HttpWebRequest.Create(new Uri(restUrl));
           // request.Headers[HttpRequestHeader.Accept] = "text/xml";

            request.BeginGetResponse(new AsyncCallback(DownloadTopicListCompleted),

            request);

            return;
        }
        private void DownloadTopicListCompleted(IAsyncResult asynchronousResult)
        {
            HttpWebRequest request =

               (HttpWebRequest)asynchronousResult.AsyncState;

            HttpWebResponse response =

              (HttpWebResponse)request.EndGetResponse(asynchronousResult);

            using (StreamReader streamReader1 =

              new StreamReader(response.GetResponseStream()))
            {

                string resultString = streamReader1.ReadToEnd();

                object o = DeserializeTopicList(resultString);
                TopicList topics = (TopicList)o;

                if (TopicsDownloaded != null)
                    TopicsDownloaded(this, new TopicsDownloadedEventArgs(topics, DateTime.UtcNow));

            }
        }

        
        public void GetTags()
        {

            CategoryList categories = new CategoryList();

            string restUrl = BASE_URL + "/tags/top/?format=xml";

            HttpWebRequest request =

            (HttpWebRequest)HttpWebRequest.Create(new Uri(restUrl));
           // request.Headers[HttpRequestHeader.Accept] = "text/xml";

            request.BeginGetResponse(new AsyncCallback(DownloadTagListCompleted),

            request);


            return;
        }
        private void DownloadTagListCompleted(IAsyncResult asynchronousResult)
        {
            HttpWebRequest request =

               (HttpWebRequest)asynchronousResult.AsyncState;

            HttpWebResponse response =

              (HttpWebResponse)request.EndGetResponse(asynchronousResult);

            using (StreamReader streamReader1 =

              new StreamReader(response.GetResponseStream()))
            {

                string resultString = streamReader1.ReadToEnd();

                object o = DeserializeTagList(resultString);
                TagList tags = (TagList)o;

                if (TagsDownloaded != null)
                    TagsDownloaded(this, new TagsDownloadedEventArgs(tags, DateTime.UtcNow));

            }
        }

        
        public void GetQuestionsForTopic(string topicSlug,int pageNumber,int pageSize)
        {

            NuggetList nuggets = new NuggetList();

            string restUrl = BASE_URL + "/questions/in/" + topicSlug + "/page/" + pageNumber.ToString() + "?format=xml";

            HttpWebRequest request =

            (HttpWebRequest)HttpWebRequest.Create(new Uri(restUrl));
           // request.Headers[HttpRequestHeader.Accept] = "text/xml";

            request.BeginGetResponse(new AsyncCallback(DownloadQuestionListCompleted),

            request);

            return;
        }
        private void DownloadQuestionListCompleted(IAsyncResult asynchronousResult)
        {
            HttpWebRequest request =

               (HttpWebRequest)asynchronousResult.AsyncState;

            HttpWebResponse response =

              (HttpWebResponse)request.EndGetResponse(asynchronousResult);

            using (StreamReader streamReader1 =

              new StreamReader(response.GetResponseStream()))
            {

                string resultString = streamReader1.ReadToEnd();

                object o = DeserializeNuggetList(resultString);
                NuggetList nuggets = (NuggetList)o;

                if (QuestionsDownloaded != null)
                    QuestionsDownloaded(this, new QuestionsDownloadedEventArgs(nuggets, DateTime.UtcNow));

            }
        }

        public void GetQuestionsForTag(string tagSlug, int pageNumber, int pageSize)
        {

            //TODO:Add Paging to the URL string

            NuggetList nuggets = new NuggetList();

            string restUrl = BASE_URL + "/questions/tagged/" + tagSlug + "/?format=xml";

            HttpWebRequest request =

            (HttpWebRequest)HttpWebRequest.Create(new Uri(restUrl));
            //request.Headers[HttpRequestHeader.Accept] = "text/xml";

            request.BeginGetResponse(new AsyncCallback(DownloadTagQuestionListCompleted),

            request);

            return;
        }
        private void DownloadTagQuestionListCompleted(IAsyncResult asynchronousResult)
        {
            HttpWebRequest request =

               (HttpWebRequest)asynchronousResult.AsyncState;

            HttpWebResponse response =

              (HttpWebResponse)request.EndGetResponse(asynchronousResult);

            using (StreamReader streamReader1 =

              new StreamReader(response.GetResponseStream()))
            {

                string resultString = streamReader1.ReadToEnd();

                object o = DeserializeNuggetList(resultString);
                NuggetList nuggets = (NuggetList)o;

                if (QuestionsDownloaded != null)
                    QuestionsDownloaded(this, new QuestionsDownloadedEventArgs(nuggets, DateTime.UtcNow));

            }
        }


        public void GetUsers()
        {

            CategoryList categories = new CategoryList();

            string restUrl = BASE_URL + "/users/?format=xml";

            HttpWebRequest request =

            (HttpWebRequest)HttpWebRequest.Create(new Uri(restUrl));
            //request.Headers[HttpRequestHeader.Accept] = "text/xml";

            request.BeginGetResponse(new AsyncCallback(DownloadUserListCompleted),

            request);


            return;
        }
        private void DownloadUserListCompleted(IAsyncResult asynchronousResult)
        {
            HttpWebRequest request =

               (HttpWebRequest)asynchronousResult.AsyncState;

            HttpWebResponse response =

              (HttpWebResponse)request.EndGetResponse(asynchronousResult);

            using (StreamReader streamReader1 =

              new StreamReader(response.GetResponseStream()))
            {

                string resultString = streamReader1.ReadToEnd();

                object o = DeserializeUserList(resultString);
                UserList users = (UserList)o;

                if (UsersDownloaded != null)
                    UsersDownloaded(this, new UsersDownloadedEventArgs(users, DateTime.UtcNow));

            }
        }


        #region DeserializeFooList
        public CategoryList DeserializeCategoryList(String pXmlizedString)
        {

            try
            {
                XmlSerializer xs = new XmlSerializer(typeof(CategoryList));

                MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Encoding = Encoding.UTF8;
                System.Xml.XmlWriter xmlTextWriter = System.Xml.XmlWriter.Create(memoryStream, settings);

                //XDocument doc = new XDocument(pXmlizedString);


                return (CategoryList)xs.Deserialize(memoryStream);

            }

            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
                return null;
            }
        }
        public TopicList DeserializeTopicList(String pXmlizedString)
        {

            try
            {
                XmlSerializer xs = new XmlSerializer(typeof(TopicList));

                MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Encoding = Encoding.UTF8;
                System.Xml.XmlWriter xmlTextWriter = System.Xml.XmlWriter.Create(memoryStream, settings);

                return (TopicList)xs.Deserialize(memoryStream);

            }

            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
                return null;
            }
        }
        public TagList DeserializeTagList(String pXmlizedString)
        {

            try
            {
                XmlSerializer xs = new XmlSerializer(typeof(TagList));

                MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Encoding = Encoding.UTF8;
                System.Xml.XmlWriter xmlTextWriter = System.Xml.XmlWriter.Create(memoryStream, settings);

                return (TagList)xs.Deserialize(memoryStream);

            }

            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
                return null;
            }
        }
        public NuggetList DeserializeNuggetList(String pXmlizedString)
        {

            try
            {
                XmlSerializer xs = new XmlSerializer(typeof(NuggetList));

                MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Encoding = Encoding.UTF8;
                System.Xml.XmlWriter xmlTextWriter = System.Xml.XmlWriter.Create(memoryStream, settings);

                return (NuggetList)xs.Deserialize(memoryStream);

            }

            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
                return null;
            }
        }
        public UserList DeserializeUserList(String pXmlizedString)
        {

            try
            {
                XmlSerializer xs = new XmlSerializer(typeof(UserList));

                MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Encoding = Encoding.UTF8;
                System.Xml.XmlWriter xmlTextWriter = System.Xml.XmlWriter.Create(memoryStream, settings);

                return (UserList)xs.Deserialize(memoryStream);

            }

            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
                return null;
            }
        }
        public User DeserializeUser(String pXmlizedString)
        {

            try
            {
                XmlSerializer xs = new XmlSerializer(typeof(User));

                MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Encoding = Encoding.UTF8;
                System.Xml.XmlWriter xmlTextWriter = System.Xml.XmlWriter.Create(memoryStream, settings);

                return (User)xs.Deserialize(memoryStream);

            }

            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
                return null;
            }
        }
        #endregion


        private String UTF8ByteArrayToString(Byte[] characters)
        {

            UTF8Encoding encoding = new UTF8Encoding();

            String constructedString = encoding.GetString(characters, 0, characters.Length);

            return (constructedString);

        }
        public Byte[] StringToUTF8ByteArray(String pXmlString)
        {

            UTF8Encoding encoding = new UTF8Encoding();

            Byte[] byteArray = encoding.GetBytes(pXmlString);

            return byteArray;

        } 


        

    }

    public class SignInCompletedEventArgs : EventArgs
    {
        public bool Succeeded { get; set; }
        public string ErrorMessage { get; set; }
        public User UserAccount { get; set; }

        public SignInCompletedEventArgs(bool succeeded, string errorMessage)
        {
            Succeeded = succeeded;
            ErrorMessage = errorMessage;
        }
    }

    public class RegistrationCompletedEventArgs : EventArgs
    {

        public User User { get; set; }
        public RegistrationCompletedEventArgs(User user)
        {
            User = user;
        }

    }

    public class QuestionPostedEventArgs : EventArgs
    {

        public Nugget Question { get; set; }
        public DateTime UpdatedDateTime { get; set; }
        public QuestionPostedEventArgs(Nugget question, DateTime updatedDateTime)
        {
            Question = question;
            UpdatedDateTime = updatedDateTime;
        }

    }

    public class CategoriesDownloadedEventArgs : EventArgs
    {

        public CategoryList Categories { get; set; }
        public DateTime UpdatedDateTime { get; set; }
        public CategoriesDownloadedEventArgs(CategoryList categories, DateTime updatedDateTime)
        {
            Categories = categories;
            UpdatedDateTime = updatedDateTime;
        }

    }
    public class TopicsDownloadedEventArgs : EventArgs
    {

        public TopicList Topics { get; set; }
        public DateTime UpdatedDateTime { get; set; }
        public TopicsDownloadedEventArgs(TopicList topics, DateTime updatedDateTime)
        { 
            Topics = topics;
            UpdatedDateTime = updatedDateTime;
        }

    }
    public class TagsDownloadedEventArgs : EventArgs
    {

        public TagList Tags { get; set; }
        public DateTime UpdatedDateTime { get; set; }
        public TagsDownloadedEventArgs(TagList tags, DateTime updatedDateTime)
        {
            Tags = tags;
            UpdatedDateTime = updatedDateTime;
        }

    }
    public class UsersDownloadedEventArgs : EventArgs
    {

        public UserList Users { get; set; }
        public DateTime UpdatedDateTime { get; set; }
        public UsersDownloadedEventArgs(UserList users, DateTime updatedDateTime)
        {
            Users = users;
            UpdatedDateTime = updatedDateTime;
        }

    }
    public class QuestionsDownloadedEventArgs : EventArgs
    {

        public NuggetList Nuggets { get; set; }
        public DateTime UpdatedDateTime { get; set; }
        public QuestionsDownloadedEventArgs(NuggetList nuggets, DateTime updatedDateTime)
        {
            Nuggets = nuggets;
            UpdatedDateTime = updatedDateTime;
        }

    }

}
